import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { xzqhTreeSelectListApi } from '@/api/wyf/xzqh/select';
import { h } from 'vue';
import { sjlyOptionsListApi } from '@/api/wyf/pms/select';
import { gxqyOptionsListApi } from '@/api/wyf/user/gxqySelect';
import { gxdwTreeSelectListApi } from '@/api/wyf/gxdw/select';
// import { rules } from '/@/utils/helper/validator';
// import { render } from '/@/utils/common/renderUtils';
// import { getWeekMonthQuarterYear } from '/@/utils';
// import { h } from 'vue';
// //列表数据
export const policeColumns: BasicColumn[] = [
  // {
  //   title: '区域',
  //   align: 'center',
  //   dataIndex: 'gxqys_dictText',
  //   width: 300,
  //   customRender: ({ record }) => {
  //     if (record['gxqys_dictText']) {
  //       const items = record['gxqys_dictText'].split(',');
  //       return h(
  //         'div',
  //         {
  //           style: {
  //             whiteSpace: 'pre-line',
  //           },
  //         },
  //         items.join('\n')
  //       );
  //     }
  //     return [];
  //   },
  // },
  // {
  //   title: '区域编号',
  //   align: 'center',
  //   dataIndex: 'gxqys',
  //   customRender: ({ record }) => {
  //     if (record['gxqys']) {
  //       let items: any = [];
  //       if (typeof record['gxqys'] === 'string') {
  //         items = record['gxqys'].split(',');
  //       } else if (Array.isArray(record['gxqys'])) {
  //         items = record['gxqys'];
  //       }
  //       return h(
  //         'div',
  //         {
  //           style: {
  //             whiteSpace: 'pre-line',
  //           },
  //         },
  //         items.join('\n')
  //       );
  //     }
  //     return [];
  //   },
  // },
  {
    title: '管辖单位',
    align: 'center',
    dataIndex: 'gxqys',
    customRender: ({ record }) => {
      if (record['gxqys']) {
        let items: any = [];
        if (typeof record['gxqys'] == 'string') {
          items = record['gxqys_dictText'].split(',');
        } else if (Array.isArray(record['gxqys'])) {
          items = record['gxqys'];
        }
        return h(
          'div',
          {
            style: {
              whiteSpace: 'pre-line',
            },
          },
          items.join('\n')
        );
      }
      return [];
    },
  },
  {
    title: '管辖单位编号',
    align: 'center',
    dataIndex: 'gxqys',
  },
  {
    title: '警员姓名',
    align: 'center',
    dataIndex: 'realname',
  },
  {
    title: '警员警号',
    align: 'center',
    dataIndex: 'jh',
  },
  // {
  //   title: '登录账号',
  //   align: 'center',
  //   dataIndex: 'username',
  // },
  // {
  //   title: '账号密码',
  //   align: 'center',
  //   dataIndex: 'password',
  // },
  {
    title: '状态',
    dataIndex: 'status_dictText',
    width: 80,
  },
];
export const pmsColumns: BasicColumn[] = [
  {
    title: '单位名称',
    align: 'center',
    dataIndex: 'pmsid_dictText',
  },
  {
    title: '姓名',
    align: 'center',
    dataIndex: 'realname',
  },
  {
    title: '联系人电话',
    align: 'center',
    dataIndex: 'phone',
  },

  {
    title: '登录账号',
    align: 'center',
    dataIndex: 'username',
  },
  // {
  //   title: '账号密码',
  //   align: 'center',
  //   dataIndex: 'password',
  // },
  {
    title: '状态',
    dataIndex: 'status_dictText',
    width: 80,
  },
];
//查询数据
export const searchPoliceFormSchema: FormSchema[] = [
  {
    label: '警号',
    field: 'jh',
    component: 'Input',
    //colProps: {span: 6},
  },
  {
    label: '姓名',
    field: 'realname',
    component: 'Input',
    //colProps: {span: 6},
  },
  // {
  //   field: 'gxqys',
  //   label: '管辖区域',
  //   component: 'ApiTreeSelect',
  //   componentProps: {
  //     api: xzqhTreeSelectListApi,
  //     params: {},
  //     resultField: 'result',
  //     multiple: true,
  //   },
  // },
  {
    field: 'gxqy',
    label: '管辖单位',
    //component: 'ApiTreeSelect',
    component: 'JCascader',
    componentProps: {
      api: gxqyOptionsListApi,
      params: {},
      //resultField: 'title',
      // fieldNames: {
      //   label: 'title',
      //   value: 'value',
      // },
      //multiple: false,
      changeOnSelect: true,
    },
  },
];
//查询数据
export const searchPmsFormSchema: FormSchema[] = [
  {
    label: '单位名称',
    field: 'pmsid',
    component: 'ApiSelect', //渲染的组件
    //defaultValue: '', //设置默认值
    componentProps: {
      api: sjlyOptionsListApi,
      resultField: 'result',
      labelField: 'mc',
      valueField: 'id',
    },
  },
  {
    label: '负责人电话',
    field: 'phone',
    component: 'Input',
    //colProps: {span: 6},
  },
];
//表单数据
export const formPmsSchema: FormSchema[] = [
  {
    label: '单位名称',
    field: 'pmsid',
    component: 'ApiSelect', //渲染的组件
    //defaultValue: '', //设置默认值
    componentProps: {
      api: sjlyOptionsListApi,
      resultField: 'result',
      labelField: 'mc',
      valueField: 'id',
    },
    required: true,
  },
  {
    label: '联系电话',
    field: 'phone',
    component: 'Input',
    required: true,
  },
  {
    label: '账号名称',
    field: 'username',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '作为登录账号',
    },
  },
  {
    label: '账号密码',
    field: 'password',
    component: 'Input',
    componentProps: {
      placeholder: '修改时，为空代表不修改密码',
    },
    required: ({ model }) => {
      return !model.id;
    },
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];
//表单数据
export const formPoliceSchema: FormSchema[] = [
  {
    label: '管辖单位',
    field: 'gxqys',
    component: 'ApiTreeSelect',
    componentProps: {
      api: gxdwTreeSelectListApi,
      params: {},
      resultField: 'result',
      multiple: true,
    },
    required: true,
  },
  {
    label: '警员姓名',
    field: 'realname',
    component: 'Input',
    required: true,
  },
  {
    label: '警员编号',
    field: 'jh',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '作为登录账号',
    },
  },
  {
    label: '账号密码',
    field: 'password',
    component: 'Input',
    componentProps: {
      placeholder: '修改时，为空代表不修改密码',
    },
    required: ({ model }) => {
      return !model.id;
    },
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

// 高级查询数据
export const superQuerySchema = {
  mc: { title: '单位名称', order: 0, view: 'text', type: 'string' },
  fzrlxdh: { title: '负责人联系电话', order: 1, view: 'text', type: 'string' },
  appkey: { title: 'appkey', order: 2, view: 'text', type: 'string' },
  appsecret: { title: 'appsecret', order: 3, view: 'text', type: 'string' },
};

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
